<template>
    <div>
        <hd-tab :tabs="tabs"/>
        <el-form ref="form" :inline="false" :model="form" label-width="80px" size="normal">
            <el-card :body-style="{ padding: '20px' }" shadow="never">
                <div slot="header">
                    员工管理
                </div>
                <el-form-item label="员工姓名">
                    <el-input v-model="form.name" clearable placeholder="简介说明"></el-input>
                    <hd-error name="name"/>
                </el-form-item>
                <el-form-item label="介绍">
                    <el-input v-model="form.introduce" clearable placeholder="员工介绍"></el-input>
                    <hd-error name="introduce"/>
                </el-form-item>
                <el-form-item label="性别">
                    <el-radio-group v-model="form.sex">
                        <el-radio :label="1">男</el-radio>
                        <el-radio :label="0">女</el-radio>
                    </el-radio-group>
                    <hd-error name="sex"/>
                </el-form-item>
                <el-form-item label="图片">
                    <hd-image v-model="form.preview"></hd-image>
                    <hd-error name="preview"/>
                </el-form-item>
                <el-form-item label="经验">
                    <el-input v-model="form.experience" clearable placeholder="经验" rows="8" type="textarea"></el-input>
                    <hd-error name="experience"/>
                </el-form-item>
                <el-form-item label="金牌员工">
                    <el-radio-group v-model="form.gold">
                        <el-radio :label="1">是</el-radio>
                        <el-radio :label="0">否</el-radio>
                    </el-radio-group>
                    <hd-error name="gold"/>
                </el-form-item>
                <el-form-item label="工作年限">
                    <el-input v-model="form.year" placeholder="工作年限" type="number"></el-input>
                    <hd-error name="year"/>
                </el-form-item>
                <el-button type="primary" @click="onSubmit">提交</el-button>

            </el-card>
        </el-form>

    </div>
</template>

<script>
import tabs from './tabs'

export default {
    route: false,
    props: ['id'],
    data() {
        return {
            tabs,
            form: {}
        }
    },
    async created() {
        if (this.id) this.form = await this.axios.get(`admin/staff/${this.id}`)
    },
    methods: {
        async onSubmit() {
            const url = this.id ? `admin/staff/${this.id}` : `admin/staff`
            await this.axios[this.id ? 'put' : 'post'](url, this.form)
            // this.$router.push({name: 'admin.staff.index'});
        }
    }
}
</script>

<style>

</style>
